<template>
  <div class="wrap">
    <div class="w-title">
      我卖出的
    </div>
    <a-tabs @change="getSell" v-model="type">
      <a-tab-pane tab="全部" key="all"></a-tab-pane>
      <a-tab-pane tab="交易中" key="1"></a-tab-pane>
      <a-tab-pane tab="交易完成" key="3"></a-tab-pane>
      <a-tab-pane tab="已关闭" key="0"></a-tab-pane>
      <a-tab-pane tab="售后" key="2"></a-tab-pane>
      <a-input-search
        slot="tabBarExtraContent"
        placeholder="输入订单短号/商品编号/关键字"
        v-model="search"
        @search="getSell"
        enterButton="搜索商品"
        class="search"
      />
    </a-tabs>

    <a-select defaultValue="全部商品类型" style="width: 220px" v-model="cateId" @change="getSell">
      <a-select-option v-for="(item,index) in arrSelect" :key="index" :value="item.key">{{item.val}}</a-select-option>
    </a-select>
    <a-table
      :columns="columns"
      :dataSource="list"
      :pagination="false"
      rowKey="order_id"
      class="table"
    >
      <template slot="name" slot-scope="text, record">
        <a-row type="flex">
          <div>
            <img :src="record.game_icon" alt srcset class="table-img" />
          </div>
          <div>
            <div class="table-n">{{record.title}}</div>
            <!-- <div>商品类型：游戏币</div> -->
            <div>{{record.list_name}}-{{record.wow}}-{{record.twow}}</div>
          </div>
        </a-row>
      </template>
      <template slot="price" slot-scope="text">{{text}}</template>
      <template slot="order_number" slot-scope="text">{{text}}</template>
      <template slot="game_type" slot-scope="text">{{text}}</template>
      <template slot="create_time" slot-scope="text">{{text}}</template>
      <template slot="operation" slot-scope="text,record">
        <!-- <template slot="sold" slot-scope="text">{{text}}</template> -->
        <a-button type="link" v-if="record.type  == 1" @click="handleBtn()" >显示</a-button>
        <a-button type="link" v-if="record.type  == 2" @click="handleBtn(record, 2)" >查看</a-button>
      </template>
    </a-table>
    <div class="pagination">
      <a-pagination showQuickJumper v-model="page" :total="total" @change="onChange" />
    </div>

    <a-modal :title="'申请退款'" v-model="refund" :footer="null">
      <div class="refund">
        <div class="r-one">
          <img class="r-img" :src="reason.game_icon">
          <div class="ro-title">{{reason.game_name}}</div>
        </div>
        <div class="r-two">
          <div class="rt-item">
            <div class="ri-title">退款金额：</div>
            <div>¥{{reason.price}}</div>
          </div>
          <div class="rt-item">
            <div class="ri-title">退款原因：</div>
            <div>
              {{reason.title}}
            </div>
          </div>
          <div class="rt-item">
            <div class="ri-title">退款说明：</div>
            <div>
              {{reason.test}}
            </div>
          </div>
          <div class="rt-item">
            <div class="ri-title">上传凭证：</div>
            <div>
              <img v-if="reason.image" :src="reason.image" alt="icon" style="width: 102px; height: 102px;" />
            </div>
          </div>
        </div>
        <div>
          <a-button @click="handleOk(2)" type="primary">退款</a-button>
          <a-button @click="handleOk(3)" type="primary">拒绝退款</a-button>
        </div>
      </div>
    </a-modal>


    
  </div>
</template>

<script>
import { MY_SELL, GET_APPLY, BUTTON_MONEY } from "../server";
const columns = [
  {
    title: "商品",
    dataIndex: "name",
    scopedSlots: { customRender: "name" }
  },
  {
    title: "金额（元）",
    dataIndex: "price",
    scopedSlots: { customRender: "price" }
  },
  {
    title: "订单号",
    dataIndex: "order_number",
    scopedSlots: { customRender: "order_number" }
  },
  {
    title: "订单状态",
    dataIndex: "game_type",
    scopedSlots: { customRender: "game_type" }
  },
  {
    title: "时间",
    dataIndex: "create_time",
    scopedSlots: { customRender: "create_time" }
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];

export default {
  layout: "main",
  data() {
    return {
      arrSelect: [
        { key: "all", val: "全部商品类型" },
        { key: "1", val: "账号" },
        { key: "2", val: "装备" },
        { key: "3", val: "游戏币" },
        { key: "4", val: "深渊票" }
      ],
      columns,
      list: [],
      total: 0,
      page: 1,
      type: "all",
      cateId: "all",
      search: "",
      refund: false,
      reason: {}
    };
  },
  created() {
    if (this.$route.params.tid) {
      this.type = this.$route.params.tid;
    }
    this.getSell();
  },
  methods: {
    getSell() {
      MY_SELL({
        page: this.page,
        pageshow: 10,
        type: this.type,
        cate_id: this.cateId,
        search: this.search
      }).then(res => {
        if (res) {
          this.list = res.data.list;
          this.total = res.data.count;
        } else {
          this.list = [];
        }
      });
    },
    onChange(page) {
      this.page = page;
      this.getSell();
    },
    handleBtn(item, type) {
      if (type == 2) {
        GET_APPLY({
          order_id: item.order_id
        }).then(res => {
          let {code, data, msg} = res
          if (code != 200) {
            this.$message.error(msg);
          } else {
            this.reason = data
            this.refund = true
          }
        })
      }
    },
    handleOk(type) {
      BUTTON_MONEY({
        order_id: this.reason.order_id,
        type
      }).then(res => {
        let {code, msg} = res
        if (code != 200) {
          this.$message.error(msg)
          this.refund = false
        } else {
          this.$message.success(msg)
          this.getSell()
          this.refund = false
        }
      })
    },
  }
};
</script>
<style lang="less" scoped>
.wrap {
  border: 3px solid #0084ff;
  border-radius: 6px;
  padding: 10px;
  .w-title {
    height: 40px;
    line-height: 40px;
    background: #0084ff;
    color: #fff;
    margin-bottom: 20px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: bold;
    padding-left: 16px;
  }
}
.search {
  width: 330px;
}
.table {
  margin-top: 20px;
  .table-n {
    width: 200px;
    height: 40px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .table-img {
    width: 80px;
    height: 80px;
    margin-right: 20px;
  }
}
.pagination {
  margin: 70px auto 60px;
  text-align: center;
}
.refund {
  padding: 10px;
  .r-one {
    display: flex;
    margin-bottom: 20px;
    .r-img {
      width: 80px;
      height: 80px;
      margin-right: 20px;
    }
    .r-title {
      flex: 1;
    }
  }
  .r-two {
    .rt-item {
      display: flex;
      margin-bottom: 10px;
      .ri-title {
        margin-right: 10px;
        min-width: 70px;
      }
    }
  }
}
</style>